package p.sunmes.les.util;

public class CalcUtil {

	/**
	 * C=Math.sqrt(a*a+b*b);
	 * @param lenA
	 * @param lenB
	 * @return
	 */
	public static float calcSqrtLen(float a, float b) {
		float cc = a * a + b * b;
		if (cc > 0) {
			return (float) (Math.sqrt(cc));
		} else {
			return 0;
		}
	}

	public static float[] calcPointMove(float cx, float cy, float x, float y,
			float r) {
		float[] op = new float[] { x, y };
		float dx = cx - x;
		float dy = cy - y;
		float len = (float) Math.sqrt(dx * dx + dy * dy);
		if (len >= r) {
			return op;
		}
		float p = (r - len) / r;
		op[0] = x - dx * p;
		op[1] = y - dy * p;
		return op;
	}

	public static float len(float xa, float ya, float xb, float yb) {
		float dx = xa - xb;
		float dy = ya - yb;
		return (float) Math.sqrt(dx * dx + dy * dy);
	}

}
